package com.xinqi.modules.sys.textbook.controller.app;

import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.R;
import com.xinqi.modules.sys.textbook.dto.req.CloudTextbookContentQueryDTO;
import com.xinqi.modules.sys.textbook.dto.rsp.CloudTextbookContentResultDTO;
import com.xinqi.modules.sys.textbook.service.CloudTextbookContentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 云课本课堂内容APP控制层
 *
 * @author: linkai
 * @date: 2023/04/25
 */
@Tag(name = "APP-云课本", description = "云课本App接口")
@RestController
@RequestMapping("/app/cloud-textbook")
@RequiredArgsConstructor
public class CloudTextbookContentAppController {
    private final CloudTextbookContentService cloudTextbookContentService;

    /**
     * 云课本课堂内容-分页
     */
    @Operation(summary = "云课本课堂内容-分页")
    @GetMapping("/{textbookId}/content/page")
    public R<PageInfo<CloudTextbookContentResultDTO>> page(@Parameter(description = "云课本ID", example = "100001") @PathVariable("textbookId") Long textbookId,
                                                           @ParameterObject CloudTextbookContentQueryDTO dto) {
        dto.setBookId(textbookId);
        PageInfo<CloudTextbookContentResultDTO> page = cloudTextbookContentService.page(dto, dto);
        return R.data(page);
    }

    /**
     * 云课本课堂内容-详情
     */
    @Operation(summary = "云课本课堂内容-详情")
    @GetMapping("/{textbookId}/content/{id}")
    public R<CloudTextbookContentResultDTO> findById(@Parameter(description = "云课本ID", example = "100001") @PathVariable("textbookId") Long textbookId,
                                                     @Parameter(description = "id", example = "100001") @PathVariable("id") Long id) {
        CloudTextbookContentResultDTO dto = cloudTextbookContentService.findById(id);
        return R.data(dto);
    }
}
